from sqlalchemy import Column, Integer, String, Text, DateTime, DECIMAL, ForeignKey
from sqlalchemy.sql import func
from app.database import Base

class Issue(Base):
    __tablename__ = "issues"

    id = Column(Integer, primary_key=True, index=True)
    title = Column(String(200), nullable=False)
    description = Column(Text, nullable=False)
    type = Column(String(20), nullable=False)  # customer, internal
    category = Column(String(50), nullable=False)  # hardware, software, firmware等
    priority = Column(String(20), nullable=False)  # low, medium, high, urgent
    status = Column(String(20), nullable=False, default="open")  # open, in_progress, resolved, closed, rejected
    submitter_id = Column(Integer, ForeignKey("users.id"), nullable=False)
    assignee_id = Column(Integer, ForeignKey("users.id"))
    similarity_score = Column(DECIMAL(5,2))
    matched_case_id = Column(Integer, ForeignKey("cases.id"))
    created_at = Column(DateTime, server_default=func.now())
    updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
    closed_at = Column(DateTime)